/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.worldscale.javase.wslib.urm;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import net.worldscale.xp.wslib.urm.URI;
import net.worldscale.xp.wslib.urm.URM;
import net.worldscale.xp.wslib.urm.io.IConnection;
import net.worldscale.xp.wslib.urm.io.IConnectionFactory;
import net.worldscale.xp.wslib.urm.util.IResourceConnection;

/**
 *
 * @author Kun
 */
public class ImplResourceConnection implements IResourceConnection {

    private static class MyFactory implements IConnectionFactory {

        public String getScheme() {
            return "resource";
        }

        public IConnection open(String uri) throws IOException {
            return new ImplResourceConnection(uri);
        }
    }

    public static IConnectionFactory getFactory() {
        return new MyFactory();
    }
    private final URI mURI;

    private ImplResourceConnection(String uri) throws IOException {
        mURI = URM.getInstance().newURI(uri);
    }

    public String getEncoding() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public long getLength() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getType() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public DataOutputStream openDataOutputStream() throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public OutputStream openOutputStream() throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void close() throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public DataInputStream openDataInputStream() throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public InputStream openInputStream() throws IOException {
        String name = "/res" + this.mURI.getPath();
        return "".getClass().getResourceAsStream(name);
    }
}
